package com.coder520.user.service;

import com.coder520.common.utils.SecurityUtils;
import com.coder520.user.dao.UserMapper;
import com.coder520.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;


/**
 * Created by Administrator on 2017-7-7.
 */
@Service("userServiceImp")
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional
    public int createUser(User user) throws UnsupportedEncodingException, NoSuchAlgorithmException {

        user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));

        userMapper.insertSelective(user);
        return 0;
    }

    /**
     *@Author Jay
     *@Date 2017-7-8 11:15
     *@Description     根据用户名查询用户
     */
    @Override
    public User findUserByUsername(String username) {
        User user = userMapper.selectByUsername(username);

        return user;
    }
}
